using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraController : MonoBehaviour
{
    public float dumping = 1.5f; //�����������
    public Vector2 offset = new Vector2(2f, 1f); //�������� ������ ������������ ���������
    private Transform player; //��������� ���������
    private int lastX; //���� ��������� ��� ������� ��������


    public float leftLimit;
    public float rightLimit;
    public float bottomLimit;
    public float upperLimit;

    private void Start()
    {
        upperLimit = 23.5f;
                bottomLimit = -4f;
                rightLimit = 26f;
                leftLimit = -24.5f;
        offset = new Vector2(Mathf.Abs(offset.x), offset.y); //���������� ��������
                                                             // FindPlayer(isLeft);
        FindPlayer();
    }

    public void FindPlayer()
    {
        player = GameObject.FindGameObjectWithTag("Player").transform;
        lastX = Mathf.RoundToInt(player.position.x);

        transform.position = new Vector3(player.position.x + offset.x, player.position.y + offset.y, transform.position.z);

    }

    private void LateUpdate()
    {
        if (player)
        {
            Vector3 target = new Vector3(player.position.x + offset.x, player.position.y + offset.y, transform.position.z);

            transform.position = target;

          transform.position = new Vector3
                (
                Mathf.Clamp(transform.position.x, leftLimit, rightLimit),
                Mathf.Clamp(transform.position.y, bottomLimit, upperLimit),
               transform.position.z
              );
        }
    }

    private void OnDrawGizmos()
    {
        Gizmos.color = Color.red;
        Gizmos.DrawLine(new Vector2(leftLimit, upperLimit), new Vector2(rightLimit, upperLimit));
        Gizmos.DrawLine(new Vector2(leftLimit, bottomLimit), new Vector2(rightLimit, bottomLimit));
        Gizmos.DrawLine(new Vector2(leftLimit, upperLimit), new Vector2(leftLimit, bottomLimit));
        Gizmos.DrawLine(new Vector2(rightLimit, upperLimit), new Vector2(rightLimit, bottomLimit));
    }

    public void CahngeLimet(TpPoint.NameNextLocations Name)
    {
        switch (((int)Name))
        {
            case 0:
                Debug.Log("Главная сцена");
                upperLimit = 23.5f;
                bottomLimit = -4f;
                rightLimit = 26f;
                leftLimit = -24.5f;
                break;
            case 1:
                 Debug.Log("Лес");
                upperLimit = 32.6f;
                bottomLimit = -4f;
                rightLimit = -58.8f;
                leftLimit = -97.7f;
                break;
            case 2:
                 Debug.Log("Пляж");
                upperLimit = -23.8f;
                bottomLimit = -46.1f;
                rightLimit = 92.5f;
                leftLimit = 60.3f;
                break;
            case 3:
                 Debug.Log("Отель");
               upperLimit = 22.1f;
                bottomLimit = -4.56f;
                rightLimit = 92.5f;
                leftLimit = 60.1f;
                break;
            case 4:
                 Debug.Log("Дом");
                upperLimit = 69.7f;
                bottomLimit = 65.46f;
                rightLimit = 79.5f;
                leftLimit = 78.8f;
                break;
            case 5:
                 Debug.Log("Секрет");
                upperLimit = 23.5f;
                bottomLimit = -4f;
                rightLimit = 26f;
                leftLimit = -24.5f;
                break;
            case 6:
                 Debug.Log("Рум4");
                upperLimit = 106.2f;
                bottomLimit = 106.2f;
                rightLimit = 94.2f;
                leftLimit = 94.2f;
                break;
            default:
                Debug.Log("Нет такого названия локации");
                upperLimit = 23.5f;
                bottomLimit = -4f;
                rightLimit = 26f;
                leftLimit = -24.5f;
                break;           
        }
    


    }
    


    
}
